package cn.kgc.houduan.controller;

import cn.kgc.houduan.pojo.Person;
import cn.kgc.houduan.pojo.ResultEntity;
import cn.kgc.houduan.service.PersonService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-06-04 8:27
 */
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@Api(tags = "人员调动相关接口",description = "提供用户相关的Rest API")
public class PersonController {

    @Resource
    PersonService personService;
    @ApiOperation("查询全部")
    @RequestMapping("/selectPerson")
    @ApiResponses({
            @ApiResponse(code = 400,message = "请求参数问题"),
            @ApiResponse(code = 404,message = "请求路径没有或页面跳转路劲不对"),
            @ApiResponse(code = 405,message = "请求类型不正确"),
            @ApiResponse(code = 500,message = "后端程序出错")

    })
    public ResultEntity<List<Person>> selectPerson(){
        List<Person> people = personService.selectPerson();
        return ResultEntity.successWithoutData(people);
    }


    //增加
    @ApiOperation("增加人员")
    @ApiResponses({
            @ApiResponse(code = 400,message = "请求参数问题"),
            @ApiResponse(code = 404,message = "请求路径没有或页面跳转路劲不对"),
            @ApiResponse(code = 405,message = "请求类型不正确"),
            @ApiResponse(code = 500,message = "后端程序出错")

    })
    @RequestMapping("/addPerson")
    public ResultEntity<Integer>  addPerson(@RequestBody Person person){
        Integer integer = personService.addPerson(person);
        return ResultEntity.successWithoutData(integer);
    }

    //删除
    @ApiOperation("查询数量")
    @ApiResponses({
            @ApiResponse(code = 400,message = "请求参数问题"),
            @ApiResponse(code = 404,message = "请求路径没有或页面跳转路劲不对"),
            @ApiResponse(code = 405,message = "请求类型不正确"),
            @ApiResponse(code = 500,message = "后端程序出错")

    })
    @ApiImplicitParam(name="id",value = "根据id删除",required = false)
    @RequestMapping(value = "/deletePerson",produces ="application/json;charset=UTF-8")
    public ResultEntity<Integer>  deletePerson(Integer id){
        Integer integer = personService.deletePerson(id);
        return ResultEntity.successWithoutData(integer);
    }
}
